package nl.vu.few.ibivu.biomodels.shared;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Id;
import javax.persistence.PrePersist;

import com.google.appengine.api.users.User;
import com.googlecode.objectify.annotation.Indexed;
import com.googlecode.objectify.annotation.Unindexed;

public class UserProfile implements Serializable {

	private static final long serialVersionUID = -3995332166048928123L;
	private @Id Long id;
	private @Indexed User user;
	private @Unindexed UserTitle title;
	private @Unindexed String firstName;
	private @Indexed String lastName;
	private @Indexed Date creationTime;
	private @Unindexed boolean smartConnections = true;
	
	@SuppressWarnings("unused")
	@PrePersist
	private void PrePersist() {
		if (creationTime == null)
			creationTime = new Date();
	}
	
	public Long getId() {
		return id;
	}
	
	public Date getCreationTime() {
		return creationTime;
	}
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public boolean useSmartConnections() {
		return smartConnections;
	}

	public void setSmartConnections(boolean smartConnections) {
		this.smartConnections = smartConnections;
	}
	
	@Override
	public String toString() {
		String r = "";
		if (firstName != null)
			r = firstName;
		if (lastName != null)
			r = r + " " + lastName;
		if (!r.isEmpty()) {
			if (title != null)
				r = title + " " + r;
		}
		else {
			r = user.getEmail();
		}
		return r;
	}

}
